﻿/* 
 * Copyright (C) 2014 Mehdi El Gueddari
 * http://mehdi.me
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */
namespace EntityFramework.DbContextScope
{
    /// <summary>
    /// Indicates whether or not a new DbContextScope will join the ambient scope.
    /// 指示新的DbContextScope是否将加入环境作用域。
    /// </summary>
    public enum DbContextScopeOption
    {
        /// <summary>
        /// Join the ambient DbContextScope if one exists. Creates a new
        /// one otherwise.
        /// 
        /// This is what you want in most cases. Joining the existing ambient scope
        /// ensures that all code within a business transaction uses the same DbContext
        /// instance and that all changes made by service methods called within that 
        /// business transaction are either committed or rolled back atomically when the top-level
        /// scope completes (i.e. it ensures that there are no partial commits). 
        ///加入环境DbContextScope（如果存在）。创建新的
        ///另外一个。
        ///
        ///在大多数情况下，这就是你想要的。加入现有环境范围
        ///确保业务事务中的所有代码使用相同的DbContext
        ///实例中调用的服务方法所做的所有更改
        ///当顶层
        ///作用域完成（即，它确保没有部分提交）。
        /// </summary>
        JoinExisting,

        /// <summary>
        /// Ignore the ambient DbContextScope (if any) and force the creation of 
        /// a new DbContextScope. 
        /// 
        /// This is an advanced feature that should be used with great care. 
        /// 
        /// When forcing the creation of a new scope, new DbContext instances will be 
        /// created within that inner scope instead of re-using the DbContext instances that
        /// the parent scope (if any) is using. 
        /// 
        /// Any changes made to entities within that inner scope will therefore get persisted 
        /// to the database when SaveChanges() is called in the inner scope regardless of wether 
        /// or not the parent scope is successful.
        /// 
        /// You would typically do this to ensure that the changes made within the inner scope 
        /// are always persisted regardless of the outcome of the overall business transaction
        /// (e.g. to persist the results of an operation, such as a remote API call, that
        /// cannot be rolled back or to persist audit or log entries that must not be rolled back
        /// regardless of the outcome of the business transaction). 
        /// 
        ///忽略环境DbContextScope（如果有），并强制创建
        ///一个新的DbContextScope。
        ///
        ///这是一个高级功能，应该非常小心地使用。
        ///
        ///当强制创建新作用域时，新的DbContext实例将
        ///在该内部范围内创建，而不是重新使用
        ///父作用域（如果有）正在使用。
        ///
        ///因此，对该内部范围内的实体所做的任何更改都将被持久化
        ///当在内部作用域中调用SaveChanges（）时，无论
        ///父作用域是否成功。
        ///
        ///您通常这样做是为了确保在内部范围内所做的更改
        ///无论整个业务事务的结果如何，始终保持
        ///（例如，保存操作的结果，例如远程API调用
        ///无法回滚或保留不能回滚的审核或日志项
        ///无论业务交易的结果如何）。
        /// </summary>
        ForceCreateNew
    }
}
